<template>
    <div id="tmpl">
        <div class="title">
            <h4 v-text="data.title"></h4>
            <p>{{data.add_time | datefmt('YYYY-MM-DD')}} {{data.click}}次浏览</p>
        </div>
        <div id="content" v-html="data.content">
             
        </div>
        <!--实现评论组件  父组件向子组件传值-->
        <comment :id="id"></comment>
    </div>
</template>
<script>
    import common from '../../kits/common.js'
    import {Toast} from 'mint-ui';
    import comment from '../subcom/comment.vue'
    export default {
        components:{
            //注册组件
            comment
        },
        data() {
            return {
                id: 0,
                data:{}
            }
        },
        created() {
            this.id = this.$route.params.id;
            this.getnewsinfo();
            
        },
        activated(){
            alert(123)
            console.log(document.querySelector('#content img'))
            document.querySelector('#content img').style.width="100%";
        },
        methods: {
            getnewsinfo: function () {
                var url = common.apidomain+'/api/getnew/' + this.id;
                this.$http.get(url).then(function (res) {
                    var body = res.body;
                    if (body.status != 0) {
                        Toast(data.message)
                        return;
                    }
                    console.log(res);
                    this.data=body.message[0];
                    
                })
            }
        }
    }
</script>
<style scoped>
    .title h4{
        color: #0094ff;
    }
    .title p{
        color: rgba(0, 0, 0, 0.5)
    }
    .title,#content{
        padding: 5px;
    }
    #content p{
        width: 100%;
    }
</style>